<?php

/**
 * Created by PhpStorm.
 * User: chen
 * Date: 2015/6/17
 * Time: 15:57
 */
class ShareRecordAction extends Action
{
    public function record()
    {
        import('ORG.Util.Session');
        $redirectUrl = $_GET['redirectUrl'];
        $shareUrl = $_GET['thisUrl'];
        $method = $_GET['method'];
        if ($method == 'pyq') {
            $method = 1;
        } else {
            $method = 0;
        }
        $shareRecordModel = D('ShareRecord');
        $data['openid'] = session::get('openid');
        $data['actnum'] = 1;
        $data['sharetype'] = $method;
        $data['pageurl'] = $shareUrl;
        $data['createtime'] = time();
        $shareRecordModel->data($data)->add();
        //第二次分享
        if($_GET['share']==1){
            M('User')->where(array('openid'=>session::get('openid')))->setField('share',0);
        }
        $this->addShareRecord($data);         //把分享动作写入到总库中去
        redirect($redirectUrl);
    }
    /**
     * 把分享信息写入到总库中去
     */
    public function addShareRecord($data){
        $con = mysql_connect("10.66.136.168:3306", "gjxx", "gjxx20150707");
        mysql_select_db("gjplatform", $con);
        mysql_query("SET NAMES UTF8");
        mysql_query("INSERT INTO gjxx_share_record(openid, actnum, sharetype, pageurl,createtime) VALUES ('".$data['openid']."','".$this->getActId()."','".$data['sharetype']."','".$data['pageurl']."','".$data['createtime']."')");
    }
    /**
     * 找出配置中的actId
     */
    public function getActId(){
        $setModel=D('Settings');
        $map=array();
        $map['name']='actId';
        return $setModel->where($map)->getField('value');
    }
}